﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web.Mvc;
using CodeCamp.Models.UserMailer;
using CCM = CodeCamp.Model;

namespace CodeCamp.Models.Email
{
    public class BasicEmailEdit : MailBaseModel
    {
        public BasicEmailEdit()
        {
            SubmitButtonText = "Save";
        }

        public bool EnableEmailViewEdit { get; set; }
        public bool EnableSendStatusEdit { get; set; }
        public bool EnableSendStatusView { get; set; }
        public bool EnableTestMessageEdit { get; set; }
        public Nullable<int> SiteUserId { get; set; }
        public string SubmitButtonText { get; set; }

        [MaxLength(256)]
        public string EmailView { get; set; }
        
        /// <summary>
        /// Set to determine where "back" link goes.
        /// </summary>
        public string ParentContext { get; set; }
        public string CampaignDescription { get; set; }
        public Nullable<CCM.EmailCampaign.EmailCampaignStatus> CampaignStatus { get; set; }
        public Nullable<CCM.EmailCampaign.EmailRecipientType> CampaignRecipientType { get; set; }

        [Required]
        public CCM.EmailItem.EmailSendStatus SendStatus { get; set; }

        [Required]
        public int SendStatusID
        {
            get { return (int)SendStatus; }
            set { SendStatus = CCM.EmailItem.GetSendStatus(value); }
        }

        public SelectList SendStatusSelectList
        {
            get
            {
                var statusItems = from CCM.EmailItem.EmailSendStatus s in Enum.GetValues(typeof(CCM.EmailItem.EmailSendStatus))
                                  select new { ID = (int)s, Name = s.ToString() };
                return new SelectList(statusItems, "ID", "Name", CCM.EmailItem.EmailSendStatus.Undefined.ToString());
            }
        }

        [Required]
        public bool TestMessage { get; set; }

        public Nullable<int> EmailCampaignId { get; set; }
    }
}